package synex;

import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

synchronizer BufferSimples {
	Lock acessLock = new ReentrantLock();
	Condition podeEscrever = acesslock.newCondition();
	Condition podeLer = acesslock.newCondition();
	boolean ocupado = false;
	
	synchronize(public void setBuffer(int)) with acessLock {
		before:
			await podeEscrever while(ocupado);
		after:
			ocupado = true;
			signal podeLer;
	}
	
	synchronize(public int getBuffer()) with acessLock {
		before:
			await podeLer while(!ocupado);
		after:
			ocupado = false;
			signal podeescrever;
	}
}
